<template>
  <el-container class="el-container" style="height: 100vh; border: 1px solid #eee">
    <el-aside class="el-aside" width="200px" style="background-color: #2c3e50; color: #fff">
      <el-menu class="el-menu" router
               default-active="/books"
               :default-openeds="['1']"
               background-color="#2c3e50"
               text-color="#fff"
               active-text-color="#ffd04b">
        <el-submenu class="el-submenu" index="1" popper-append-to-body>
          <template slot="title">
            <i class="el-icon-document"></i> 功能列表
          </template>
          <el-menu-item class="el-menu-item" index="/books">
            <i class="el-icon-news"></i> 图书库
          </el-menu-item>
          <el-menu-item class="el-menu-item" index="/mybooks">
            <i class="el-icon-tickets"></i> 已借阅
          </el-menu-item>
        </el-submenu>
        <el-submenu class="el-submenu" index="2" v-if="role!=='user'">
          <template  slot="title">
            <i class="el-icon-user"></i> 用户管理
          </template>
          <el-menu-item class="el-submenu-item" index="/users">
            <i class="el-icon-plus"></i> 添加用户
          </el-menu-item>
        </el-submenu>
      </el-menu>
    </el-aside>
    <el-container>
      <el-header class="el-header" style="display: flex; justify-content: space-between; align-items: center; background-color: #34495e; color: #fff;">
        <div style="font-size: 20px; font-weight: bold;">图书管理系统</div>
        <el-dropdown @command="handleCommand">
          <span class="el-dropdown-link">
            {{ uid }}<i class="el-icon-arrow-down el-icon--right"></i>
          </span>
          <el-dropdown-menu class="el-dropdown-menu" slot="dropdown">
            <el-dropdown-item class="el-dropdown-menu__item" command="logout" @click="logout">退出登录</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </el-header>
      <el-main class="el-main" style="background-color: #ecf0f1; padding: 20px;">
        <router-view/>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  data() {
    return {
      uid: this.$route.query.uid,
      role: this.$route.query.role,
    }
  },
  provide() {
    return {
      commonData: this
    };
  },
  methods: {
    logout() {
      this.$router.push({
        path: '/'
      })
    }
  }
};
</script>

<style scoped>
.el-container {
  font-family: 'Arial', sans-serif;
}

.el-header {
  font-size: 16px;
  line-height: 60px;
}

.el-dropdown-link {
  cursor: pointer;
  color: #fff;
  font-size: 16px;
}

/* 修正后的下拉菜单样式 */
.el-dropdown-menu {
  background-color: #2c3e50 !important;
  border: none !important;
}

.el-dropdown-menu .el-dropdown-menu__item {
  color: #fff !important;
  background-color: #2c3e50 !important;
}

.el-dropdown-menu .el-dropdown-menu__item:hover {
  background-color: #34495e !important;
}
.el-menu-item {
  font-size: 15px;
  color: #dcdcdc !important;
  background-color: #34495e !important;
}
.el-menu-item, .el-submenu__title {
  font-size: 16px;
}

.el-menu-item:hover, .el-submenu__title:hover {
  background-color: #34495e !important;
}
</style>